﻿using M.Warehouse.API.Application.Command.BinLocationsCommand;
using M.Warehouse.Domain;
using M.Warehouse.Repository.WarehouseInterface;
using MediatR;

namespace M.Warehouse.API.Application.CommandHandlers.BinLocationsCommandHandlers
{
    public class BinlocationsShowByRIdCommandHandlers : IRequestHandler<BinlocationsShowByRIdCommand, List<BinLocations>>
    {
        private readonly IBinLocationsRepository _binLocationsRepository;
        public BinlocationsShowByRIdCommandHandlers(IBinLocationsRepository binLocationsRepository)
        {
            _binLocationsRepository = binLocationsRepository;
        }
        public async Task<List<BinLocations>> Handle(BinlocationsShowByRIdCommand request, CancellationToken cancellationToken)
        {
            var list = await _binLocationsRepository.GetAllAsync();
            if (request.ReservoirId > 0)
            {
                list=list.Where(x=>x.ReservoirId==request.ReservoirId).ToList();
            }
            return list;
            //return (await _binLocationsRepository.GetAllAsync()).Where(x => x.ReservoirId == request.ReservoirId).ToList();
        }
    }
}
